package com.example.springboot.utils;

import com.example.springboot.config.applicationContextNameAware.SpringContextHolder;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/9/26 16:34
 */
public class SendMailUtil {
    private SendMailUtil() {

    }

    public static void send(String title, String content) {
        // 制造回滚
        int i = 1 / 0;
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        // 设置发送邮件地址
        simpleMailMessage.setFrom("1052031630@qq.com");
        // 设置发送对象的邮件地址
        simpleMailMessage.setTo("528402297@qq.com");
        // 设置主题
        simpleMailMessage.setSubject(title);
        // 设置内容
        simpleMailMessage.setText(content);
        // 拿到对象
        JavaMailSender javaMailSender = SpringContextHolder.getBean(JavaMailSender.class);
        // 发送消息
        javaMailSender.send(simpleMailMessage);

    }
}
